package com.zsc.rediscli.cluster;

import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;

import java.util.HashSet;
import java.util.concurrent.TimeUnit;

/**
 * 模拟cluster故障转移
 */
public class JedisClusterFaultTest {


    public static void main(String[] args) {
        HashSet<HostAndPort> nodeList = new HashSet<>();
        nodeList.add(new HostAndPort("192.168.56.108",7000));
        nodeList.add(new HostAndPort("192.168.56.108",7001));
        nodeList.add(new HostAndPort("192.168.56.108",7002));
//        nodeList.add(new HostAndPort("192.168.56.108",7003));
//        nodeList.add(new HostAndPort("192.168.56.108",7004));
//        nodeList.add(new HostAndPort("192.168.56.108",7005));
//        nodeList.add(new HostAndPort("192.168.56.108",7006));

        JedisCluster jedisCluster = new JedisCluster(nodeList, 1000,new GenericObjectPoolConfig());
        int i = 0 ;
        while (true){
            try{
                String key = "key" + i;
                String value = "value" + i;
                jedisCluster.set(key,value);
                System.out.println("2555");
//                System.out.println(jedisCluster.get(key));
                i++;
                TimeUnit.SECONDS.sleep(1);
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }
}
